
# value = ['离离原上草', '一岁一枯荣', '野火烧不尽', '春风吹又生']

# w 写模式，全文覆盖
# w+ 读加写
# file = open('my_test.txt', 'w+', encoding='utf-8')
# for i in value:
#     file.write(i+'\n')
# file.seek(0)  # 指针移动到文件头部
# print(file.read())
# file.close()


# a 模式，尾部追加
# file = open('my_test.txt', 'a', encoding='utf-8')
# for i in value:
#     file.write(i+'\n')
# file.close()

# r 读模式
# r+ 读+写，按字节位覆盖
# file = open('my_test.txt', 'r+', encoding='utf-8')
# file.write('坚果')
# print(file.tell())
# print(file.read(3))
# print(file.tell())
# print(file.tell())
# print(file.readline())
# print(file.tell())
# file.seek(3)
# print(file.readline())
# print(file.readline())  # 读文件时一定要注意指针位置是否正确
# print(file.readline())
# file.close()

# b 二级制方式处理文件
# file_old = open(r'C:\Users\TT\Pictures\jianpan.jpg', 'r')
# old = file_old.read()
#
# file_new = open('my_pic.jpg', 'w')
# file_new.write(old)
#
# file_old.close()
# file_new.close()

with open('my_test.txt', 'a+', encoding='utf-8') as f:
    f.seek(0)
    print(f.read())


